//
//  UIBarButtonItem+Extension.swift
//  weibo_swift
//
//  Created by dulinlong on 15/7/6.
//  Copyright © 2015年 sheji_56. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    convenience init(imageName: String, highlightedName: String?){
        
        self.init(imageName: imageName, highlightedName: highlightedName,target: nil , actionName: nil)
    }
    
    
    convenience  init(imageName: String, highlightedName: String?,target: AnyObject?, actionName: String?){
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        let name = highlightedName  ?? imageName + "_highlighted"
        btn.setBackgroundImage(UIImage(named: name), forState: UIControlState.Highlighted)
        btn.sizeToFit()
        
        if actionName != nil {
        btn.addTarget(target!, action: Selector(actionName!), forControlEvents: UIControlEvents.TouchUpInside)
        }
        
        self.init(customView: btn)
    }
}
